<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width:100%">
    <el-col>{{ nodescope.name }}</el-col>
    <el-col :span="6">
      <el-row type="flex" justify="end">
        <el-col>{{ nodescope.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 -->
          <el-dropdown>
            <span>操作<i class="el-icon-arrow-down el-icon--right" /></span>
            <el-dropdown-menu slot="dropdown">
              <!-- 因为不是原生组件，直接写@click会以为是子组件监听过来的事件，用native修饰符表示监听的就是这个组件原生的点击事件 -->
              <el-dropdown-item @click.native="addDepts(nodescope.id)">
                新建部门
              </el-dropdown-item>
              <el-dropdown-item @click.native="editDepts(nodescope.id)">
                编辑部门
              </el-dropdown-item>
              <el-dropdown-item @click.native="delDepts(nodescope.id)">
                删除部门
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

        </el-col>

      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepts } from '@/api/departments'

export default {
  props: {
    nodescope: {
      type: Object,
      required: true
    }

  },
  methods: {
    addDepts(id) {
      // console.log(1)
      console.log(id)
      this.$emit('isShowDialog', id)
    },
    editDepts(id) {
      console.log(id)
      this.$emit('editDialog', id)
    },
    async delDepts(id) {
      // 用messageBox组件提示是否确认删除,有.then,所以需要等，可以用async await,只有第一句是必须的
      await this.$confirm('是否确认删除?')
      // 发送删除请求
      await delDepts(id)
      this.$message.success('删除成功')
      // 通知父组件更新页面
      this.$emit('reload')
    }
  }

}
</script>

<style>

</style>
